package com.example.serverdemo.utils.sessionutils.sessionmanager;

import com.example.serverdemo.utils.sessionutils.session.DeviceCommunicationSession;

import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class DeviceCommunicationSessionManager {
    private static final ConcurrentHashMap<String, DeviceCommunicationSession> sessionMap = new ConcurrentHashMap<>();

    public static DeviceCommunicationSession addSession(String deviceId){
        String sessionId = deviceId;
        synchronized (sessionMap){
            DeviceCommunicationSession session = new DeviceCommunicationSession(sessionId);
            sessionMap.put(sessionId,session);
            return session;
        }
    }
    public static DeviceCommunicationSession getSession(String sessionId){
        return sessionMap.get(sessionId);
    }
    public static boolean containsSession(String sessionId){
        synchronized (sessionMap){
            return sessionMap.containsKey(sessionId);
        }
    }
    public static void removeSession(String sessionId){
        if (containsSession(sessionId)){
            sessionMap.remove(sessionId);
        }
    }
}
